package com.benben.springSecurity.weiwei;

public class JianpanMove {
    public static void main(String[] args) {
        String buttons = "zyxwvutsrqponmlkjihgfedcba";
        String word = "xyz";
        System.out.println(MoveTime(buttons,word));
        String buttons2 = "pqrstuvwxyzabcdefghijklmno";
        String word2 = "phone";
        System.out.println(MoveTime(buttons2,word2));

    }
    public static int MoveTime(String buttons,String word){
        if(buttons.length()!=26){
            return 0;
        }
        int beginTime = buttons.indexOf(word.charAt(0));
        int time = 0;
        for(int i=1;i<word.length();i++){
            time +=  Math.abs(buttons.indexOf(word.charAt(i-1)) - buttons.indexOf(word.charAt(i)));
        }
        return time+beginTime;
    }
}
